const index = {
    namespaced: true,
    state: {
        sysInfo: {},
		userInfo: uni.getStorageSync('user_info') === '' ? {} : JSON.parse(uni.getStorageSync('user_info')),
		curTab: 'statistics',
		curRole: uni.getStorageSync('user_info') === '' ? {role_name: '中心专职'} : JSON.parse(uni.getStorageSync('user_info')).role_list[0],
		loading: 0,
		curProject: uni.getStorageSync('cur_project') === '' ? {
			project_name: '',
			id: '',
			xmb_address: '',
			longitude: '',
			latitude: ''
		} : JSON.parse(uni.getStorageSync('cur_project')),
		curLocation: uni.getStorageSync('cur_location') === '' ? {
			address: '获取中...',
			longitude: '',
			latitude: '',
		} : JSON.parse(uni.getStorageSync('cur_location')),
		tempData: {}
    },
    getters: {
		getCurLocation(state) {
		    return state.curLocation;
		},
		getCurProject(state) {
		    return state.curProject;
		},
        getSysInfo(state) {
            return state.sysInfo;
        },
		getCurRole(state) {
		    return state.curRole.role_name;
		},
		getCurTab(state) {
		    return state.curTab;
		},
		getUserInfo(state) {
		    return state.userInfo;
		},
		getTempData(state) {
		    return state.tempData;
		}
    },
    mutations: {
		setCurLocation(state, params) {
		    state.curLocation = params;
		},
        setSysInfo(state, params) {
            state.sysInfo = params;
        },
		setCurRole(state, params) {
		    state.curRole = params;
		},
		setCurTab(state, params) {
		    state.curTab = params;
		},
		setUserInfo(state, params) {
		    state.userInfo = params;
		},
		setCurProject(state, params) {
		    state.curProject = params;
		},
		setLoading(state, params) {
		    state.loading = state.loading + params;
		},
		resetCurProject(state) {
			state.curProject = {
				project_name: '',
				id: '',
				xmb_address: '',
				longitude: '',
				latitude: ''
			};
		},
		setTempData(state, params) {
		    state.tempData = params;
		},
    },
    actions: {
		setTempData({ commit }, params) {
		    commit("setTempData", params);
		},
		setCurLocation({ commit }, params) {
			uni.setStorageSync('cur_location', JSON.stringify(params));
		    commit("setCurLocation", params);
		},
        setSysInfo({ commit }, params) {
            commit("setSysInfo", params);
        },
		setCurRole({ commit }, params) {
		    commit("setCurRole", params);
		},
		setCurTab({ commit }, params) {
		    commit("setCurTab", params);
		},
		setCurProject({ commit }, params) {
			uni.setStorageSync('cur_project', JSON.stringify(params));
		    commit("setCurProject", params);
		},
		setUserInfo({ commit }, params) {
			uni.setStorageSync('user_info', JSON.stringify(params));
			commit("setCurRole", params.role_list[0]);
			commit("setUserInfo", params);
		},
		setLoading({ commit }, params) {
		    commit("setLoading", params);
		},
		resetCurProject({ commit }) {
			commit("resetCurProject")
		},
		loginOut({ commit }) {
			uni.clearStorageSync();
			commit("setUserInfo", {});
			uni.redirectTo({
				url: "/pages/login/index"
			})
		}
    }
};

export default index;
